const webpack = require('webpack');
const path = require('path');
const VersionPlugin = require('./src/plugins/version-plugin');
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
function resolve(dir) {
  return path.join(__dirname, './', dir);
}
// 插件添加
const configPlugins = [];
if (process.env.NODE_ENV === 'production') {
  // 添加版本号
  configPlugins.push(new VersionPlugin({ buildPath: resolve('build/qd_build'), rootPath: resolve('/'), versionDirectory: 'static' }));
  // 添加打包性能检查
  configPlugins.push(new BundleAnalyzerPlugin());
}
module.exports = {
  productionSourceMap: false,
  configureWebpack: {
    plugins: configPlugins
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-px2rem')({ remUnit: 78 }) // 换算的基数
        ]
      }
    }
  },
  outputDir: 'build/qd_build',
  assetsDir: 'static',
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('~', resolve('public'));
  },
  filenameHashing: false,
  devServer: {
    disableHostCheck: true,
    proxy: {
      '/api': {
        target: process.env.VUE_APP_SERVER_URL, // 服务器接口域名
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
};
